home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / packer / xpkarchive / lib / genglue.rexx next >
OS/2 REXX Batch file  |  1995-03-09  |  3KB  |  181 lines

  1. /*
  2.  
  3.    ©1993 by Matthias Meixner
  4.  
  5.  
  6.    USAGE: rx genglue.rexx <inputfile.fd
  7.  
  8.  
  9.  
  10.    Format without Tags:
  11.  
  12.    function(varlist)(reglist)
  13.  
  14.  
  15.    Format with Tags:
  16.  
  17.    functionA(varlist)(reglist)
  18.  
  19.    -> functionA , function
  20.  
  21.    functionTagList(varlist)(reglist)
  22.  
  23.    ->functionTagList , functionTags
  24.  
  25.  */
  26.  
  27. basename=0
  28. public=1
  29. bias=0
  30.  
  31. line=readln(stdin)
  32. line=compress(line)
  33.  
  34. do while line~==""
  35.  
  36.    parse var line "##bias" newbias
  37.    parse var line "##base" newbase
  38.    parse var line func "(" varlist ")(" reglist ")"
  39.  
  40.    if line="##end" then
  41.       exit(0)
  42.    else if line="##public" then
  43.       public=1
  44.    else if line="##private" then
  45.       public=0
  46.    else if newbias~=="" then
  47.       bias=newbias
  48.    else if newbase~=="" then
  49.       basename=newbase
  50.    else if left(func,1)~=="*" then do
  51.       if public=="1" then do
  52.          if right(func,1)=="A" then gentags(func,reglist,1,"")
  53.          if right(func,7)=="TagList" then gentags(func,reglist,4,"s")
  54.          gencode(func,reglist)
  55.       end
  56.       bias=bias+6
  57.    end
  58.  
  59.    line=readln(stdin)
  60.    line=compress(line)
  61. end
  62.  
  63. exit(0)
  64.  
  65. gencode: procedure expose basename bias
  66.  
  67.    parse arg func,reglist
  68.  
  69.    if Open("output",func".a",w)==0 then do
  70.       say "Cannot open output file"
  71.       exit(0)
  72.    end
  73.  
  74.    saveregs=regs(reglist)
  75.  
  76.    writeln("output",'   SECTION "code",CODE')
  77.    writeln("output","   XDEF _"func)
  78.    writeln("output","   XREF "basename)
  79.  
  80.    writeln("output","_"func":")
  81.    writeln("output","   movem.l "saveregs",-(sp)")
  82.    writeln("output","   move.l  "basename",A6")
  83.  
  84.    offset=4+((length(saveregs)+1)%3)*4
  85.  
  86.    do while reglist~==""
  87.  
  88.       parse var reglist reg","reglist
  89.  
  90.       if length(reg)==2 then
  91.          writeln("output","   move.l  "offset"(sp),"reg)
  92.       else
  93.          writeln("output","   movem.l "offset"(sp),"reg)
  94.  
  95.       offset=offset+(length(reg)+1)%3*4
  96.  
  97.    end
  98.  
  99.    writeln("output","   jsr     -"bias"(A6)")
  100.    writeln("output","   movem.l (sp)+,"saveregs)
  101.    writeln("output","   rts")
  102.    writeln("output","   END")
  103.  
  104.    Close("output")
  105.  
  106.    return 0
  107.  
  108.  
  109. gentags: procedure expose basename bias
  110.  
  111.    parse arg func,reglist,trunc,tag
  112.  
  113.    saveregs=regs(reglist)
  114.  
  115.    func=left(func,length(func)-trunc)tag
  116.  
  117.    if Open("output",func".a",w)==0 then do
  118.       say "Cannot open output file"
  119.       exit(0)
  120.    end
  121.  
  122.    writeln("output",'   SECTION "code",CODE')
  123.    writeln("output","   XDEF _"func)
  124.    writeln("output","   XREF "basename)
  125.  
  126.    writeln("output","_"func":")
  127.    writeln("output","   movem.l "saveregs",-(sp)")
  128.    writeln("output","   move.l  "basename",A6")
  129.  
  130.    offset=4+((length(saveregs)+1)%3)*4
  131.  
  132.    do while reglist~==""
  133.  
  134.       parse var reglist reg","reglist
  135.  
  136.       if length(reglist)>0 then
  137.          if length(reg)==2 then
  138.             writeln("output","   move.l  "offset"(sp),"reg)
  139.          else
  140.             writeln("output","   movem.l "offset"(sp),"reg)
  141.       else
  142.          writeln("output","   lea     "offset"(sp),"reg)
  143.  
  144.       offset=offset+(length(reg)+1)%3*4
  145.    end
  146.  
  147.    writeln("output","   jsr     -"bias"(A6)")
  148.    writeln("output","   movem.l (sp)+,"saveregs)
  149.    writeln("output","   rts")
  150.  
  151.    writeln("output","   END")
  152.  
  153.    Close("output")
  154.  
  155.    return 0
  156.  
  157.  
  158. regs: procedure
  159.    parse arg reglist
  160.  
  161.    reglist=compress(reglist,",/")
  162.    reglist=upper(reglist)
  163.  
  164.    saveregs="A6"
  165.  
  166.    do while reglist~==""
  167.       reg=left(reglist,2)
  168.       reglist=right(reglist,length(reglist)-2)
  169.  
  170.       if ~(reg="D0" | reg="D1" | reg="A0" | reg="A1") then
  171.          saveregs=saveregs||"/"||reg
  172.  
  173.    end
  174.  
  175.    return(saveregs)
  176.  
  177.  
  178.  
  179.  
  180.  
  181.